package com.huawang.mdesign.model.service.constant;

import com.huawang.core.definition.mof.UMLDefinitionConstants;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;

/**
 * @author cdl
 */
@AllArgsConstructor
@Getter
public enum MilestoneKindEnum {
    STRATEGIC_ACTUAL_DEPLOYMENT(
            UAFDefinitionConstants.UAF_TABLE_STRM_STRATEGIC_ACTUAL_DEPLOYMENT,
            UMLDefinitionConstants.UAF_ActualMilestoneKind_Deployed,
            UMLDefinitionConstants.UAF_ActualMilestoneKind_NoLongerUsed,
            UMLDefinitionConstants.UAF_ActualProjectMilestone_actualResource,
            UMLDefinitionConstants.UAF_ActualProjectMilestone_actualResource,
            UMLDefinitionConstants.UAF_ActualResource,
            UMLDefinitionConstants.UAF_ActualResource_milestone
    ),
    STRATEGIC_TYPICAL_DEPLOYMENT(
            UAFDefinitionConstants.UAF_TABLE_STRM_STRATEGIC_TYPICAL_DEPLOYMENT,
            UMLDefinitionConstants.UAF_ActualMilestoneKind_InService,
            UMLDefinitionConstants.UAF_ActualMilestoneKind_OutOfService,
            UMLDefinitionConstants.UAF_ActualProjectMilestone_versionReleased,
            UMLDefinitionConstants.UAF_ActualProjectMilestone_versionWithdrawn,
            UMLDefinitionConstants.UAF_Resource,
            UMLDefinitionConstants.UAF_ResourcePerformer_milestone
    ),
    CV5_CAPACITY_ORGANIZATION_DEVELOPMENT(
            UAFDefinitionConstants.UAF_TABLE_CV5_CAPABILITY_TO_ORGANIZATIONAL_DEVELOPMENT_TABLE,
            UMLDefinitionConstants.UAF_ActualMilestoneKind_Deployed,
            UMLDefinitionConstants.UAF_ActualMilestoneKind_NoLongerUsed,
            UMLDefinitionConstants.UAF_ActualProjectMilestone_actualResource,
            UMLDefinitionConstants.UAF_ActualProjectMilestone_actualResource,
            UMLDefinitionConstants.UAF_ActualResource,
            UMLDefinitionConstants.UAF_ActualResource_milestone
    ),
    CV5_CAPACITY_ORGANIZATION_TYPICAL(
            UAFDefinitionConstants.UAF_TABLE_CV5_CAPABILITY_TO_ORGANIZATIONAL_DEVELOPMENT_TYPICAL_TABLE,
            UMLDefinitionConstants.UAF_ActualMilestoneKind_InService,
            UMLDefinitionConstants.UAF_ActualMilestoneKind_OutOfService,
            UMLDefinitionConstants.UAF_ActualProjectMilestone_versionReleased,
            UMLDefinitionConstants.UAF_ActualProjectMilestone_versionWithdrawn,
            UMLDefinitionConstants.UAF_Resource,
            UMLDefinitionConstants.UAF_ResourcePerformer_milestone
    );

    private final String tableType;

    private final String startDateKind;

    private final String endDateKind;

    private final String startKey;

    private final String endKey;

    private final String resourceKey;

    private final String milestoneKey;

    @NotNull
    public static MilestoneKindEnum getInstance(String tableType) {
        return Arrays.stream(MilestoneKindEnum.values())
                .filter(e -> Objects.equals(e.tableType, tableType))
                .findFirst()
                .orElse(STRATEGIC_ACTUAL_DEPLOYMENT);
    }

    @Nullable
    public static String getPropKey(String dateKind) {
        Map<String, String> map = new HashMap<>();
        Arrays.stream(MilestoneKindEnum.values()).forEach(e -> {
            map.put(e.startDateKind, e.startKey);
            map.put(e.endDateKind, e.endKey);
        });
        return map.get(dateKind);
    }

    @NotNull
    public static String getResourceKey(String tableType) {
        return Arrays.stream(MilestoneKindEnum.values())
                .filter(e -> Objects.equals(e.tableType, tableType))
                .findFirst()
                .map(MilestoneKindEnum::getResourceKey)
                .orElseThrow(NullPointerException::new);
    }

    @NotNull
    public static String getMilestoneKey(String tableType) {
        return Arrays.stream(MilestoneKindEnum.values())
                .filter(e -> Objects.equals(e.tableType, tableType))
                .findFirst()
                .map(MilestoneKindEnum::getMilestoneKey)
                .orElseThrow(NullPointerException::new);
    }

    @NotNull
    public static Set<String> getResourceType(String tableType) {
        Set<String> set = new HashSet<>();
        Arrays.stream(MilestoneKindEnum.values())
                .filter(e -> Objects.equals(e.tableType, tableType))
                .forEach(e -> {
                    set.add(e.getStartKey());
                    set.add(e.getEndKey());
                });
        return set;
    }
}
